
<template>
  <div class="main">
    <h2>退款管理</h2>
    <div id="table-area">
      <el-table
        v-loading="listLoading"
        :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >
        <!-- <el-table-column
          align="center"
          prop="id"
          label="编号"
          min-width="5%"
        /> -->
        <el-table-column
          label="序号"
          type="index"
          min-width="5%"
          align="center"
        >
          <template scope="scope">
            <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="orderId"
          label="订单编号"
          min-width="10%"
        />

        <el-table-column
          align="center"
          prop="userId"
          label="用户编号"
          min-width="6%"
        />

        <el-table-column
          align="center"
          prop="userName"
          label="用户姓名"
          min-width="7%"
        />

        <el-table-column
          align="center"
          prop="userPhone"
          label="手机号"
          min-width="10%"
        />

        <el-table-column
          align="center"
          prop="orgName"
          label="品牌名称"
          min-width="17%"
        />

        <el-table-column
          align="center"
          prop="campusName"
          label="机构名称"
          min-width="17%"
        />

        <el-table-column
          align="center"
          prop="state"
          label="当前状态"
          min-width="7%"
        >
          <template slot-scope="Scope">
            <span v-if="Scope.row.state==-1" style="color:red">已驳回</span>
            <span v-if="Scope.row.state==0" style="color:gray">待处理</span>
            <span v-if="Scope.row.state==1" style="color:green">已通过</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="操作" min-width="20%">
          <template slot-scope="Scope">
            <el-button v-if="Scope.row.state==0" type="primary" icon="el-icon-edit" @click="updateState(Scope.row.orderId,1)">通过</el-button>
            <el-button v-if="Scope.row.state==0" type="danger" icon="el-icon-delete" @click="updateState(Scope.row.orderId,-1)">驳回</el-button>
            <span v-if="Scope.row.state!=0" style="color:green">已完成处理</span>
          </template>
        </el-table-column>
      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[5,10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getAllRefund, updateRefundState, refund } from '@/api/refund'
import { getOrderById } from '@/api/orders'
export default {

  data() {
    // 这里存放数据
    return {
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      list: [],
      listLoading: false

    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.fetchData()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    fetchData() {
      getAllRefund().then((resp) => {
        this.list = resp.obj
      })
    },
    updateState(id, state) {
      this.$confirm('请再次确认').then(() => {
        updateRefundState(id, state).then((resp) => {
          // this.$notify({
          //   title: '操作成功',
          //   type: 'success'
          // })
          // this.fetchData()
          if (state === 1) {
            getOrderById(id).then((res) => {
              refund(resp.obj.orderId, resp.obj.oriOrderNo, resp.obj.oriTranDate, res.obj.totalPrice).then((re) => {
                console.log(re)
              })
            })
          }
          this.fetchData()
        })
      })
    }

  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style  scoped>
 #main{
        margin-left: 5px;
        margin-right: 5px;
    }

    #table-area{

        margin-left: 10px;
        margin-right: 10px;
    }
</style>
